home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / K14R7P (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  4.2 KB  |  146 lines

  1. package com.sun.java.swing.text;
  2.  
  3. import com.sun.java.swing.event.DocumentEvent;
  4. import com.sun.java.swing.event.DocumentEvent.EventType;
  5. import com.sun.java.swing.undo.CannotRedoException;
  6. import com.sun.java.swing.undo.CannotUndoException;
  7. import com.sun.java.swing.undo.CompoundEdit;
  8. import com.sun.java.swing.undo.UndoableEdit;
  9. import java.util.Hashtable;
  10.  
  11. public class AbstractDocument$DefaultDocumentEvent extends CompoundEdit implements DocumentEvent {
  12.    // $FF: synthetic field
  13.    AbstractDocument this$0;
  14.    private int offset;
  15.    private int length;
  16.    private Hashtable changeLookup;
  17.    private DocumentEvent.EventType type;
  18.  
  19.    // $FF: synthetic method
  20.    public AbstractDocument$DefaultDocumentEvent(AbstractDocument this$0, int offs, int len, DocumentEvent.EventType type) {
  21.       this.this$0 = this$0;
  22.       this.offset = offs;
  23.       this.length = len;
  24.       this.type = type;
  25.    }
  26.  
  27.    public String toString() {
  28.       return super.edits.toString();
  29.    }
  30.  
  31.    public boolean addEdit(UndoableEdit anEdit) {
  32.       if (this.changeLookup == null && super.edits.size() > 10) {
  33.          this.changeLookup = new Hashtable();
  34.          int n = super.edits.size();
  35.  
  36.          for(int i = 0; i < n; ++i) {
  37.             Object o = super.edits.elementAt(i);
  38.             if (o instanceof DocumentEvent.ElementChange) {
  39.                DocumentEvent.ElementChange ec = (DocumentEvent.ElementChange)o;
  40.                this.changeLookup.put(ec.getElement(), ec);
  41.             }
  42.          }
  43.       }
  44.  
  45.       if (this.changeLookup != null && anEdit instanceof DocumentEvent.ElementChange) {
  46.          DocumentEvent.ElementChange ec = (DocumentEvent.ElementChange)anEdit;
  47.          this.changeLookup.put(ec.getElement(), ec);
  48.       }
  49.  
  50.       return super.addEdit(anEdit);
  51.    }
  52.  
  53.    public void redo() throws CannotRedoException {
  54.       this.this$0.writeLock();
  55.  
  56.       try {
  57.          super.redo();
  58.          if (this.type == EventType.INSERT) {
  59.             this.this$0.fireInsertUpdate(this);
  60.          } else if (this.type == EventType.REMOVE) {
  61.             this.this$0.fireRemoveUpdate(this);
  62.          } else {
  63.             this.this$0.fireChangedUpdate(this);
  64.          }
  65.       } finally {
  66.          this.this$0.writeUnlock();
  67.       }
  68.  
  69.    }
  70.  
  71.    public void undo() throws CannotUndoException {
  72.       this.this$0.writeLock();
  73.  
  74.       try {
  75.          super.undo();
  76.          if (this.type == EventType.REMOVE) {
  77.             this.this$0.fireInsertUpdate(this);
  78.          } else if (this.type == EventType.INSERT) {
  79.             this.this$0.fireRemoveUpdate(this);
  80.          } else {
  81.             this.this$0.fireChangedUpdate(this);
  82.          }
  83.       } finally {
  84.          this.this$0.writeUnlock();
  85.       }
  86.  
  87.    }
  88.  
  89.    public boolean isSignificant() {
  90.       return true;
  91.    }
  92.  
  93.    public String getPresentationName() {
  94.       DocumentEvent.EventType type = this.getType();
  95.       if (type == EventType.INSERT) {
  96.          return "addition";
  97.       } else {
  98.          return type == EventType.REMOVE ? "deletion" : "style change";
  99.       }
  100.    }
  101.  
  102.    public String getUndoPresentationName() {
  103.       return "Undo " + this.getPresentationName();
  104.    }
  105.  
  106.    public String getRedoPresentationName() {
  107.       return "Redo " + this.getPresentationName();
  108.    }
  109.  
  110.    public DocumentEvent.EventType getType() {
  111.       return this.type;
  112.    }
  113.  
  114.    public int getOffset() {
  115.       return this.offset;
  116.    }
  117.  
  118.    public int getLength() {
  119.       return this.length;
  120.    }
  121.  
  122.    public Document getDocument() {
  123.       return this.this$0;
  124.    }
  125.  
  126.    public DocumentEvent.ElementChange getChange(Element elem) {
  127.       if (this.changeLookup != null) {
  128.          return (DocumentEvent.ElementChange)this.changeLookup.get(elem);
  129.       } else {
  130.          int n = super.edits.size();
  131.  
  132.          for(int i = 0; i < n; ++i) {
  133.             Object o = super.edits.elementAt(i);
  134.             if (o instanceof DocumentEvent.ElementChange) {
  135.                DocumentEvent.ElementChange c = (DocumentEvent.ElementChange)o;
  136.                if (c.getElement() == elem) {
  137.                   return c;
  138.                }
  139.             }
  140.          }
  141.  
  142.          return null;
  143.       }
  144.    }
  145. }
  146.